﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using KetBanBonPhuong;
using System.Data.SqlClient;

public partial class Admin_UserControls_PhotoDetail : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["PhotoID"] != null)
        {
            int PhotoID = Convert.ToInt32(Request.QueryString["PhotoID"].ToString());
            Photo p = Photo.GetInfo(PhotoID);
            captionLabel.Text = p.PhotoCaption;
            created_dateRadDatePicker.SelectedDate = p.PhotoCreateDate;
            if (p.IsShown)
            {
                is_shownCheckBox.Checked = true;
            }
            else
            {
                is_shownCheckBox.Checked = false;
            }
            string url = "../../Files/Album/" + Album.GetInfo(p.AlbumID).Path + "/" + p.FileName;
            photoImage.ImageUrl = url;
        }
    }
    protected void is_shownCheckBox_CheckedChanged(object sender, EventArgs e)
    {
        if (Request.QueryString["PhotoID"] != null)
        {
            int PhotoID = Convert.ToInt32(Request.QueryString["PhotoID"].ToString());
            Photo p = Photo.GetInfo(PhotoID);
            if (is_shownCheckBox.Checked)
            {
                p.IsShown = true;
            }
            else
            {
                p.IsShown = false;
            }
            try
            {
                Photo.Update(p);
            }
            catch (SqlException)
            {
                return;
            }
            resultLabel.Text = "(*) Cập nhật thành công!";
        }
    }
}
